#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(){
  //写一个没有人回收的僵尸进程
  pid_t ret = fork();

  if(ret == 0){
    int cnt = 0;
    while(cnt < 5){
      printf("I am child! My pid is:%d!  My ppid is:%d!\n",getpid(),getppid());
      sleep(1);
      ++cnt;
    }
    exit(-1); //子进程跑五秒后退出，父进程仍继续跑，不去回收子进程的资源
  }
  else{
    while(1){
      printf("I am father! My pid is:%d! My ppid is:%d!\n ",getpid(),getppid());
      sleep(1);
    }
  }
  return 0;


//fork的用法
 // pid_t ret = fork();
 // if(ret == 0){
 //   while(1){
 //     printf("I am child! My pid is:%d!  My ppid is:%d!\n",getpid(),getppid());
 //     sleep(1);
 //   }
 // }
 // else{
 //   while(1){
 //     printf("I am father! My pid is:%d! My ppid is:%d!\n ",getpid(),getppid());
 //     sleep(1);
 //   }
 // }
 // return 0;
}
